//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

typedef struct _ResourceConverterInstance *		ResourceConverterInstance;
/*
void _EXPORT_ CreateResourceConverter (const char *path, const char *log, ResourceConverterInstance &rc);
void _EXPORT_ DestroyResourceConverter (ResourceConverterInstance rc);
bool _EXPORT_ ConvertResources (ResourceConverterInstance rc, const char *config);
*/


#define DECL_RESOURCE_CONVERTER( _libName ) \
	struct ResConv \
	{ \
		Engine::UXTypes::Library	lib; \
		ResourceConverterInstance	rc; \
		\
		bool (* createResourceConverter) (const char *, const char *, ResourceConverterInstance &); \
		void (* destroyResourceConverter) (ResourceConverterInstance); \
		bool (* convertResources) (ResourceConverterInstance, const char *); \
		\
		ResConv () : rc(null), createResourceConverter(null), \
			destroyResourceConverter(null), convertResources(null) \
		{ \
			bool	loaded = lib.FindAndLoad( _libName, 8 ); \
			ASSERT_EXT( loaded, "library not loaded" ); \
			\
			loaded &= lib.GetProc( createResourceConverter,		"CreateResourceConverter"	); \
			loaded &= lib.GetProc( destroyResourceConverter,	"DestroyResourceConverter"	); \
			loaded &= lib.GetProc( convertResources,			"ConvertResources"			); \
			ASSERT_EXT( loaded, "can't get address of functions" ); \
		} \
		\
		~ResConv () \
		{ \
			destroyResourceConverter( rc ); \
			rc = null; \
			\
			lib.Unload(); \
		} \
		\
		bool Create (const char *path, const char *log) \
		{ \
			return createResourceConverter( path, log, rc ); \
		} \
		\
		bool Convert (const char *config) \
		{ \
			return convertResources( rc, config ); \
		} \
		\
		static bool Run (const char *path, const char *log, const char *config) \
		{ \
			ResConv	rc; \
			return rc.Create( path, log ) and rc.Convert( config ); \
		} \
	}
